package com.woniu.woniuk16.controller;


import com.woniu.woniuk16.dto.AccountsDto;
import com.woniu.woniuk16.entity.WoniuAccount;
import com.woniu.woniuk16.model.Result;
import com.woniu.woniuk16.param.EmailParam;
import com.woniu.woniuk16.param.FindAccountParam;
import com.woniu.woniuk16.service.WoniuAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.login.AccountException;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tiangle
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/woniuAccount")
public class WoniuAccountController {
    @Autowired
    private WoniuAccountService woniuAccountService;
    @GetMapping("/nonelogin")
    public Result nonelogin() {
        System.out.println(111);
        return Result.getInstance(null).setCode(30000).setMessage("未登陆");
    }

//    @GetMapping("/getAll")
//    public Result getAll(){
//        List<WoniuAccount> list = woniuAccountService.list();
//        return Result.getInstance(list);
//    }
    @PostMapping("/like")
    public Result getAccounts(@RequestBody FindAccountParam findAccountParam){

        AccountsDto account = woniuAccountService.getAccount(findAccountParam);
        return Result.getInstance(account);
    }

    @PostMapping("/email")
    public Result changeEmail(@RequestBody EmailParam emailParam) throws AccountException {
        boolean b = woniuAccountService.changeEmail(emailParam);
        if (b) return Result.getInstance(null).setMessage("修改成功");
        throw new AccountException("修改失败");
    }


}

